package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.dto.RepairPageDto;
import com.example.entity.Repair;
import com.example.service.RepairService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin/repair")
@CrossOrigin
public class RepairController {
    @Autowired
    private RepairService repairService;

    @PostMapping("/add")
    public Result add(@RequestBody Repair repair) {
        repairService.add(repair);
        return Result.success();
    }

    @GetMapping("/page")
    public Result<PageResult> page(RepairPageDto repairPageDto) {
        log.info("维修信息查询：{}",repairPageDto);
        PageResult page =  repairService.page(repairPageDto);
        return Result.success(page);
    }

    @DeleteMapping("{dno}/{pno}")
    public Result deleteByDno(@PathVariable String dno,@PathVariable String pno){
        log.info("dno{}",dno);
        repairService.deleteByDno(dno,pno);
        return Result.success();
    }
    @PutMapping
    public Result update(@RequestBody Repair repair){

        repairService.update(repair);
        return Result.success();
    }
}
